package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("adminSetmealController")
@Slf4j
@RequestMapping("/admin/setmeal")
@Api(tags = "套餐管理")
@RequiredArgsConstructor
public class SetmealController {
    private final SetmealService setmealService;

    /**
     * 分页查询套餐信息
     *
     * @param pageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("套餐分页查询")
    public Result<PageResult> pageSetmeal(SetmealPageQueryDTO pageQueryDTO) {
        log.info("套餐分页查询参数: {}", pageQueryDTO);
        return Result.success(setmealService.pageSetmeal(pageQueryDTO));
    }

    /**
     * 新增套餐
     *
     * @return
     */
    @PostMapping
    @ApiOperation("新增套餐")
    public Result save(@RequestBody SetmealDTO setmealDTO) {
        log.info("新增套餐参数: {}", setmealDTO);
        setmealService.save(setmealDTO);
        return Result.success();
    }

    /**
     * 套餐的启用和停用
     *
     * @param status
     * @param id
     * @return
     */
    @PostMapping("/status/{status}")
    @ApiOperation("套餐的启用和停用")
    @ApiImplicitParams(
            {@ApiImplicitParam(name = "status", value = "套餐状态", required = true, dataType = "int"),
                    @ApiImplicitParam(name = "id", value = "套餐ID", required = true, dataType = "long")}
    )
    public Result startOrStop(@PathVariable Integer status, Long id) {
        log.info("套餐的启用和停用参数: status={}, id={}", status, id);
        setmealService.startOrStop(status, id);
        return Result.success();
    }

    /**
     * 删除套餐
     *
     * @param ids
     * @return
     */
    @DeleteMapping
    @ApiOperation("删除套餐")
    @ApiImplicitParam(name = "ids", value = "套餐ID列表", required = true, dataType = "List<Long>")
    public Result delete(@RequestParam List<Long> ids) {
        log.info("删除套餐参数: {}", ids);
        setmealService.deleteByIds(ids);
        return Result.success();
    }

    /**
     * 根据ID查询套餐
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据ID查询套餐")
    @ApiImplicitParam(name = "id", value = "套餐ID", required = true, dataType = "Long")
    public Result<SetmealDTO> getById(@PathVariable Long id) {
        return Result.success(setmealService.getById(id));
    }

    /**
     * 更新套餐
     *
     * @param setmealDTO
     * @return
     */
    @PutMapping
    @ApiOperation("更新套餐")
    public Result update(@RequestBody SetmealDTO setmealDTO) {
        log.info("更新套餐参数: {}", setmealDTO);
        setmealService.update(setmealDTO);
        return Result.success();
    }
}
